//
//  BVRechargeViewController.m
//  BuyVegetable
//
//  Created by yushanchang on 16/10/6.
//  Copyright © 2016年 com.yinding. All rights reserved.
//

#import "BVRechargeViewController.h"
#define NormalImage [UIImage imageNamed:@"huikongxinyuan"]
#define SelectImage [UIImage imageNamed:@"hongkongxinyuan"]


@interface BVRechargeViewController ()

@property (nonatomic, strong) UIButton *selectedBtn;

@end

@implementation BVRechargeViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationItem.title = @"账户充值";
}

- (void)setMoneyButton:(NSArray *)moneyButton {
    _moneyButton = moneyButton;
    int i = 0;
    for (UIButton *btn in self.moneyButton) {
        [btn setImage:NormalImage forState:UIControlStateNormal];
        [btn setImage:SelectImage forState:UIControlStateSelected];
        [btn addTarget:self action:@selector(buttonClick:) forControlEvents:UIControlEventTouchUpInside];
        if (!i) {
            [self buttonClick:btn];
        }
        i++;
    }
}

- (void)setAlipayButton:(UIButton *)alipayButton {
    _alipayButton = alipayButton;
//    alipayButton.selected = YES;
    [self payWayClick:alipayButton];
}

#pragma mark -
#pragma mark - 充值金额按钮点击事件
- (void)buttonClick:(UIButton *)sender {
    if (sender != self.selectedBtn) {
        self.selectedBtn.selected = NO;
        sender.selected = YES;
        self.selectedBtn = sender;
    }else{
        self.selectedBtn.selected = YES;
    }
    _otherView.text = sender.titleLabel.text;
}

#pragma mark -
#pragma mark - 支付方式选择
- (IBAction)payWayClick:(UIButton *)sender {
    
    if (sender.selected) {
        sender.selected = NO;
        if (sender == self.alipayButton) {
            _weChatButton.selected = YES;
            
        } else if (sender == self.weChatButton){
            self.alipayButton.selected = YES;
        }
        
    } else {
        sender.selected = YES;
        if (sender == self.alipayButton) {
            self.weChatButton.selected = NO;
        } else if (sender == self.weChatButton){
            self.alipayButton.selected = NO;
        }
    }
    [sender setImage:NormalImage forState:UIControlStateNormal];
    [sender setImage:SelectImage forState:UIControlStateSelected];
}


#pragma mark -
#pragma mark - 确认按钮点击事件
- (IBAction)confirmClick:(id)sender {
    
    if (self.alipayButton.selected == YES && self.weChatButton.selected == NO) {
        NSLog(@"支付宝支付");
    } else {
        NSLog(@"微信支付");
    }
}

- (IBAction)tap:(id)sender {
    [self.view endEditing:YES];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
